package com.qf.controller;

import com.qf.pojo.MusicList;
import com.qf.service.MusicListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController("/musiclist")
public class MusicListController {
    @Autowired
    MusicListService musicListService;

    @RequestMapping("/findMusicListAll")
    public List<MusicList> findAll(){
        return  musicListService.findAll();
    }
    @RequestMapping("/findMusicListByName")
    public List<MusicList> findByName(@RequestBody Map map){
        String name= (String)map.get("name");
        return  musicListService.findByName(name);
    }

    @RequestMapping("/addMusicList")
    public String add(MusicList musicList){
        int i = musicListService.add(musicList);
        if(i==1){
            return "success";
        }else{
            return "fail";
        }
    }


    @RequestMapping("/updateMusicList")
    public String update(MusicList musicList){
        int i = musicListService.update(musicList);
        if(i==1){
            return "success";
        }else{
            return "fail";
        }
    }

    @RequestMapping("/deleteByName")
    public void delete(@RequestBody Map map){
        String name= (String)map.get("name");
        musicListService.delete(name);
    }

}
